package com.fast.alden.admin.web.controller.monitor;

import com.fast.alden.admin.service.SysOperationLogService;
import com.fast.alden.data.model.SysOperationLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Nullable;
import jakarta.annotation.Resource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;

/**
 * 操作日志管理控制器
 */
@Tag(name = "SysOperationLogController", description = "操作日志管理")
@RestController
@RequestMapping("/operation-log")
public class SysOperationLogController {
    @Resource
    private SysOperationLogService operationLogService;

    @Operation(summary = "分页查询", security = @SecurityRequirement(name = "openApiSecurityScheme"))
    @PostMapping("/page")
    public Page<SysOperationLog> page(@RequestBody @Nullable SysOperationLog searchVo,
                                      @RequestParam(name = "no", defaultValue = "0") int no,
                                      @RequestParam(name = "size", defaultValue = "10") int size
    ) {
        return operationLogService.search(searchVo, PageRequest.of(no, size, Sort.by(Sort.Direction.DESC, "lastModifiedTime")));
    }

    @Operation(summary = "根据ID查询", security = @SecurityRequirement(name = "openApiSecurityScheme"))
    @GetMapping("/retrieve/{id}")
    public SysOperationLog retrieve(@PathVariable("id") Long id) {
        return operationLogService.retrieve(id);
    }
}
